package net.ibizsys.eclipse.studio.project;

import java.io.File;
import java.util.List;

import net.ibizsys.eclipse.studio.data.Project;

/**
 * Maven项目合并批处理文件构建对象
 * 
 * @author <a href='http://www.weibo.com/xjtoo' target='_blank'>Enmaai</a>
 */
public class MavenBatchBuilder extends BaseBatchBuilder
{
	@Override
	protected void buildLnxBatch(StringBuilder builder, Project project, List<Project> dependProjects, String destPath)
	{
		String strProjectPath = destPath + File.separator + project.getName() + File.separator + "src" + File.separator + "main";

		for (Project proj : dependProjects)
		{
			String strPath = destPath + File.separator + proj.getName();

			switch (proj.getType())
			{
			case USR:
			case PUB:
			case SRVPUB:
			case SRVUSR:
			case WEBPUB:
			case WEBUSR:
			case Unknown:
				continue;
			case APPPUB:
				//builder.append(String.format("mkdir %1$s/webapp/%2$s \n", strProjectPath, proj.getAppname()));
				//builder.append(String.format("rsync -ruv %1$s/* %2$s/webapp/%3$s \n", strPath, strProjectPath, proj.getAppname()));
				break;
			case APPUSR:
				//builder.append(String.format("mkdir %1$s/webapp/%2$s \n", strProjectPath, proj.getAppname()));
				//builder.append(String.format("rsync -rv %1$s/* %2$s/webapp/%3$s \n", strPath, strProjectPath, proj.getAppname()));
				break;
			}
		}
	}

	@Override
	protected void buildWinBatch(StringBuilder builder, Project project, List<Project> dependProjects, String destPath)
	{
		destPath = destPath.replaceAll("/", "\\\\");
		//定义参数
		builder.append("cd .. \n");
		builder.append("echo set source home: \n");
		builder.append("Set SOURCE_HOME="+destPath+"\n");
		builder.append("echo set target home: \n");
		builder.append("Set TARGET_HOME="+destPath+"\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\"+project.getName()+"\n");
		
		for (Project proj : dependProjects)
		{
			switch (proj.getType())
			{
			case USR:
			case PUB:
			case SRVPUB:
			case SRVUSR:
			case WEBPUB:
			case WEBUSR:
			case Unknown:
				continue;
			case APPPUB:
				builder.append(String.format("mkdir %1$s\\%2$s\n", "%TARGET_HOME%",proj.getAppname()));
				builder.append(String.format("xcopy %1$s\\%2$s\\* %3$s\\%4$s\\ /E/Y/D\n", "%SOURCE_HOME%",project.getName(), "%TARGET_HOME%",proj.getAppname()));
				break;
			case APPUSR:
				builder.append(String.format("mkdir %1$s\\%2$s\n", "%TARGET_HOME%",proj.getAppname()));
				builder.append(String.format("xcopy %1$s\\%2$s\\* %3$s\\%4$s\\ /E/Y\n", "%SOURCE_HOME%",project.getName(), "%TARGET_HOME%",proj.getAppname()));
				break;
			}
		}
		
		builder.append("pause\n");
	}
}
